package net.asfun.jvalog.misc;

import net.asfun.jvalog.http.ResponseHandle;
import net.asfun.jvalog.service.DbAccessor;

public class ThreadHelper {
	
	private static ThreadLocal<ThreadCarrier> cm = new ThreadLocal<ThreadCarrier>();
	
	public static void startup() {
		ThreadCarrier carrier = new ThreadCarrier();
		cm.set(carrier);
	}
	
	public static ResponseHandle header() {
		return cm.get().header;
	}
	
	public static DbAccessor dba() {
		return cm.get().da;
	}
	
	public static void shutdown() {
		cm.get().da.close();
	}
	
	private static class ThreadCarrier {
		
		public ResponseHandle header;
		
		public DbAccessor da;
		
		public ThreadCarrier() {
			header = new ResponseHandle();
			da = new DbAccessor();
		}
	}
}
